<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>${abbreviate(scheme.name, 30)} - 766 SMART HOME</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="${base}/resources/shop/css/product.css" rel="stylesheet" type="text/css" />
	<link href="${base}/resources/shop/css/customer.css" rel="stylesheet" type="text/css" />
	<!-- 共有的CSS样式 -->
	<link href="${base}/resources/shop/css/bootstrap.min.css" rel="stylesheet">
	
	<!-- 顶部的CSS样式 -->
	<link href="${base}/resources/shop/css/head.css" rel="stylesheet">
	<!-- 底部的CSS样式 -->
	<link href="${base}/resources/shop/css/footer.css" rel="stylesheet">
	<!-- 自己定义的CSS样式 -->
	<link href="${base}/resources/shop/css/product_content.css" rel="stylesheet">
	<link href="${base}/resources/shop/css/common_product.css" rel="stylesheet">
	
	<script  type="text/javascript" src="${base}/resources/shop/js/jquery.js"></script>
	<script  type="text/javascript" src="${base}/resources/shop/js/public.js"></script>
	<script  type="text/javascript" src="${base}/resources/shop/js/common.js"></script>
	<script  type="text/javascript" src="${base}/resources/shop/js/common_another.js"></script>

</head>
<body>
	[#include "/shop/include/ng_header.ftl" /]
	<div class="container productContent">
		<div class="span6">
			<div class="hotProduct">
				<div class="title">${message("shop.product.hotProduct")}</div>
				<ul>
					[@product_list productCategoryId = productCategory.id count = 6 orderBy="monthSales desc"]
						[#list products as product]
							<li[#if !product_has_next] class="last"[/#if]>
								[#-- 
								<div class="hotProductImage">
									<!--此处放图片-->
									<img style="display: inline;"
									src="http://www.766home.com/upload/image/201605/b656d7ac-2cd2-4cce-91a4-1fe78c9ab521.jpg"
									data-original="http://www.766home.com/upload/image/201605/b656d7ac-2cd2-4cce-91a4-1fe78c9ab521.jpg"
									width="170" height="170">
								</div>
								 --]
								<div>
									<a href="${base}${product.path}" title="${product.name}">${abbreviate(product.name, 30)}</a>
								</div>
								[#if product.scoreCount > 0]
									<div>
										<div>${message("Product.score")}: </div>
										<div class="score${(product.score * 2)?string("0")}"></div>
										<div>${product.score?string("0.0")}</div>
									</div>
								[/#if]
								<div>${message("Product.price")}: <strong>${currency(product.price, true, true)}</strong></div>
								<div>${message("Product.monthSales")}: <em>${product.monthSales}</em></div>
							</li>
						[/#list]
					[/@product_list]
				</ul>
			</div>
			<div class="hotProduct advertisement" id="advertisement">

				<div class="title">广告区域</div>
				<ul>
					<li class="last">
						[#-- 
						<div class="hotProductImage">
							<!--此处放图片-->
							<img style="display: inline;"
								src="http://www.766home.com/upload/image/201605/b656d7ac-2cd2-4cce-91a4-1fe78c9ab521.jpg"
								data-original="http://www.766home.com/upload/image/201605/b656d7ac-2cd2-4cce-91a4-1fe78c9ab521.jpg"
								width="170" height="170">
						</div>
						 --] 
						<a href="/product/content/201602/549.html" title="前锋无限量家用供热/供暖中心">前锋无限量家用供热/供暖中心</a>
						<div>
							销售价: <strong>￥13986.00元</strong>
						</div>
						<div>
							月销量: <em>1</em>
						</div>
					</li>
				</ul>
			</div>
		</div>
		
		<div class="span18 last">
			<div class="clearfix">
				<div class="path">
					<ul>
						<li>
							<a href="${base}/">${message("shop.path.home")}</a>
						</li>
						<li>
							<a>
								[#list types as type]
									[#if type.id == scheme.type]
										${type.title}
									[/#if]
								[/#list]
							</a>
						</li>
						<li class="last">
							${abbreviate(scheme.name, 60,"...")}
						</li>
					</ul>
				</div>
				<div class="schemeImage productImage">
					[#if scheme.schemeImages?has_content]
						<a id="zoom" href="${scheme.schemeImages[0].large}" rel="gallery">
							<img class="medium" src="${scheme.schemeImages[0].medium}"/>
						</a>
					[#else]
						<a id="zoom" href="${setting.defaultLargeProductImage}" rel="gallery">
							<img class="medium" src="${setting.defaultMediumProductImage}" />
						</a>				
					[/#if]
					<a href="javascript:;" class="prev"></a>
					<div id="scrollable" class="scrollable">
						<div class="items">
							[#if scheme.schemeImages?has_content]
								[#list scheme.schemeImages as schemeImage]
									<a [#if schemeImage_index == 0] class="current"[/#if] href="javascript:;" rel="{gallery: 'gallery', smallimage: '${schemeImage.medium}', largeimage: '${schemeImage.large}'}"><img src="${schemeImage.thumbnail}" title="${schemeImage.title}" /></a>
								[/#list]
							[#else]
								<a class="current" href="javascript:;"><img src="${setting.defaultThumbnailProductImage}" /></a>
							[/#if]
						</div>
					</div>
					<a href="javascript:;" class="next"></a>
				</div>
				<input type="hidden" id="schemeId" value="${scheme.id}" />
				<input type="hidden" id="ktId" value="${typeIdZNKT}" />
				<input type="hidden" id="typeId" value="${scheme.type}" />
				<input type="hidden" id="schemePrice" value="${scheme.price}" />
				<input type="hidden" id="schemeAcreage" value="${scheme.acreage}" />
				<input type="hidden" id="auxiliaryUnitPrice" value="${scheme.auxiliaryUnitPrice}" />
				<input type="hidden" id="installCost" value="${scheme.installCost}" />
				<div class="name col-xs-6">${scheme.name}</div>
				<div class="sn col-xs-6">
					<div>编号: ${scheme.sn}</div>
				</div>
				<div class="info col-xs-12">
					<dl class="col-xs-6 col-lg-12">
						<dt>销售价:</dt>
						<dd>
							<strong>￥${scheme.price?string("0.00")}</strong>
						</dd>
					</dl>
					<dl class="col-xs-6 col-lg-12">
						<dt>面积(㎡):</dt>
						<dd>
							<strong>${scheme.acreage}</strong>
						</dd>
					</dl>
					<dl class="col-xs-12">
						<dt>适用面积:</dt>
						<dd>
							<strong>${scheme.beginArea}&nbsp;至&nbsp;${scheme.endArea}(㎡)</strong>
						</dd>
					</dl>
					<dl class="col-xs-12">
						<dt>适用户型:</dt>
						<dd>
							<strong>
								[#list schAttrs as schattr]
									[#list attrs as att]
										[#if att == schattr.id]
											${schattr.title}
										[/#if]
									[/#list]
								[/#list]
							</strong>
						</dd>
					</dl>
					[#if scheme.isTehui != null && scheme.isTehui && scheme.tehuiTitle != null]
						<dl class="col-xs-12">
							<dt>特惠标题:</dt>
							<dd>
								<strong>${scheme.tehuiTitle}</strong>
							</dd>
						</dl>
					[/#if]
				</div>
			</div>
		<div class="bespoke_bar clearfix col-xs-12"> 
			<div class="left col-xs-4">
				<label>方案确认</label>
			</div>
			<div class="right col-xs-8 col-lg-7">
				<div class="redPrice col-lg-5">		
					<span class="red">￥</span>
					<span class="red price" id="surePrice">${scheme.price?string("0.00")}</span>
				</div>
				<input type="button" class="bespoke_btn" id="bespokeBtn" value="立即预约"/>
			</div>
		</div>
		<div class="bespoke_table clearfix">
			<div class="left col-xs-12">
				<table>
					<thead>
						<tr>
							<th>主材名称</th>
							<th>品牌</th>
							<th>规格</th>
							<th>分类</th>
							<th>数量</th>
							<th>差价</th>
							<th>选择</th>
						</tr>
					</thead>
					<tbody id="sproductBody" data_isChange="${scheme.isChange}" data_isTehui="${scheme.isTehui}" data_isAirConditioner="${scheme.type}">
						[#list scheme.schemeProducts as sp]
							<tr class="sproductTr" 
								[#if sp.name == "电热执行器"]id="WK_TR_ID" style="display:none;" [/#if]
								[#if sp.name == "温控面板"]id="MB_TR_ID" style="display:none;" [/#if]
								[#if sp.name == "卫浴散热器"]id="SRQ_TR_ID" style="display:none;" [/#if]
								[#if sp.name == "提升泵"]id="TSB_TR_ID" style="display:none;" [/#if]
								[#if sp.name == "控制器"]id="KZQ_TR_ID" style="display:none;" [/#if]
							>
								<input type="hidden" name="spId" value="${sp.id}">
								<td class="spName" title="${sp.name}">${abbreviate(sp.name, 20, "...")}</td>
								<td class="spBrand">${sp.brand.name}</td>
								<td class="spModel">${sp.specificationValue.name}</td>
								<td class="spCategory">${sp.category.title}</td>
								<td class="spNumber">[#if sp.distType ==3]<input type="text" class="text changeNumber" value="0" style="width:14px;"/>[#else]1[/#if]</td>
								<td class="spPrice">0.00</td>
								<!--主材原价，价格不改变-->
								<input type="hidden" name="spPrice" class="price" value="${sp.price}">
								<input type="hidden" name="spCategoryId" class="spCategoryId" value="${sp.nameId}">
								<!--主材系数，有值则是有系数的，没有值表示无系数-->
								<input type="hidden" name="spCoefficient" class="spCoefficient" value="${sp.coefficient}">
								<!--类型区分值，1表示有系数，2表示无系数且不是自选商品，3表示自选商品-->
								<input type="hidden" name="distType" class="distType" value="${sp.distType}">
								<!--差价隐藏值-->
								<input type="hidden" name="hidChajia" class="hidChajia" value="0.00">
								<!--方案单排价格，用于有系数时计算-->
								<input type="hidden" name="checked_scheme_price" class="checked_scheme_price" value="${sp.price}">
								<td>
									[#if !scheme.isChange && !scheme.isTehui && !sp.isTehui && sp.name != "室外机"]
										<a href="javascript:;" class="changeWood" data_id="${sp.id}"><span class="red">[更换]</span></a>
									[/#if]
								</td>
							</tr>
						[/#list]
						<tr>
							<td colspan="7">
								[#if scheme.type == typeIdZNNQ]
									[#if scheme.category == categoryIdDL]
										<label><input type="checkbox" id="selectWK" />选择电热执行器和温控面板</label>
										<label><input type="checkbox" id="selectSRQ" />选择卫浴散热器</label>
									[/#if]
								[/#if]
								[#if scheme.type == typeIdZNKT]
									<label><input type="checkbox" id="selectTSB" />选择提升泵</label>
									<label><input type="checkbox" id="selectKZQ" />选择控制器</label>
								[/#if]
							</td>
						</tr>
						<tr>
							<td colspan="7">
								<label>合计：</label>
								<span class="red" id="subtotalPrice">0.00</span>
								<span>元</span>
							</td>
						</tr>
					</tbody>
				</table>
				<table>
					<thead>
						<tr>
							<th>方案面积(㎡)</th>
							<th>差价</th>
						</tr>
					</thead>
					<tbody id="">
						<tr>
							<td>
								<input type="text" class="text"  id="acreageText" name="acreage" value="${scheme.acreage}" style="width:60px;"/>
							</td>
							<td id="acreageChajiaTr"></td>
						</tr>
						<tr>
							<td colspan="2">
								<label>合计：</label>
								<span class="red" id="acreageChajia">0.00</span>
								<span>元</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
			<div class="right col-xs-12">
				<table>
						<tr>
							<th colspan="2">费用明细</th>
						</tr>
					<tbody>
						<tr>
							<td>名称</td>
							<td>价格</td>
						</tr>
						<tr>
							<td>方案固定价</td>
							<td id="schemeChajia">${scheme.price?string("0.00")}</td>
						</tr>
						<tr>
							<td>主材差价</td>
							<td id="zhucaiChajia">0.00</td>
						</tr>
						<tr>
							<td>面积差价</td>
							<td id="mianjiChajia">0.00</td>
						</tr>
						<tr>
							<td colspan="2">
								<label>合计：</label>
								<span class="red" id="totalChajia">${scheme.price?string("0.00")}</span>
								<span>元</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
			<div id="bar" class="bar">
				<ul>
					[#if scheme.introduction?has_content]
						<li id="introductionTab">
							<a href="#introduction">方案介绍</a>
						</li>
					[/#if]
					[#if scheme.parameter?has_content]
						<li id="parameterTab">
							<a href="#parameter">配置参数</a>
						</li>
					[/#if]
					[#if scheme.configuration?has_content]
						<li id="configurationTab">
							<a href="#configuration">设备配置</a>
						</li>
					[/#if]
					[#if scheme.auxiliaryDescript?has_content]
						<li id="auxiliaryDescriptTab">
							<a href="#auxiliaryDescript">辅材介绍</a>
						</li>
					[/#if]
				</ul>
			</div>
			[#if scheme.introduction?has_content]
				<div id="introduction" name="introduction" class="introduction">
					<div class="title">
						<strong>方案介绍</strong>
					</div>
					<div class="clearfix">
						${scheme.introduction}
					</div>
				</div>
			[/#if]
			[#if scheme.parameter?has_content]
				<div id="parameter" name="parameter" class="introduction">
					<div class="title">
						<strong>配置参数</strong>
					</div>
					<div>
						${scheme.parameter}
					</div>
				</div>
			[/#if]
			[#if scheme.configuration?has_content]
				<div id="configuration" name="configuration" class="introduction">
					<div class="title">
						<strong>设备配置</strong>
					</div>
					<div>
						${scheme.configuration}
					</div>
				</div>
			[/#if]
			[#if scheme.auxiliaryDescript?has_content]
				<div id="auxiliaryDescript" name="auxiliaryDescript" class="introduction">
					<div class="title">
						<strong>辅材介绍</strong>
					</div>
					<div>
						${scheme.auxiliaryDescript}
					</div>
				</div>
			[/#if]
		</div>
	</div>
	<div id="principalWindow" class="principalWindow">
		<div class="cover"></div>
		<div class="window_con">
			<span class="close_btn" id="closeTab"></span>
			<div class='changeMaterial'>
				<table id="selectSchemeProductTab">
					<thead>
						<tr>
							<th style="width:30px;">&nbsp;</th>
							<th>主材名称</th>
							<th>品牌</th>
							<th>规格</th>
							<th>分类</th>
							<th>差价</th>
						</tr>
					</thead>
					<tbody id="changeSchemeProductList">
						
					</tbody>
				</table>
			</div>
			<input type="button" value="确认" class="button" id="sureBtn"/>
		</div>
	</div>
	<form id="buildScheme" action="${base}/member/order/buildScheme.jhtml" method="POST">
		<input id="build_schemeId" type="hidden" name="schemeId" value=""/>
		<input id="build_jsonParam" type="hidden" name="jsonParam" value=""/>
		<input id="build_schemeArea" type="hidden" name="schemeArea" value=""/>
		<input id="build_isTemperature" type="hidden" name="isTemperature" value=""/>
		<input id="build_isDissipate" type="hidden" name="isDissipate" value=""/>
		<input id="build_isPromote" type="hidden" name="isPromote" value=""/>
		<input id="build_isController" type="hidden" name="isController" value=""/>
	</form>
	[#include "/shop/include/ng_footer.ftl" /]
</body>
	<script type="text/javascript" src="${base}/resources/shop/js/jQuery-jcContact.js"></script>
	<script type="text/javascript" src="${base}/resources/shop/js/jquery.tools.js"></script>
	<script type="text/javascript" src="${base}/resources/shop/js/jquery.jqzoom.js"></script>
	<script type="text/javascript" src="${base}/resources/shop/js/jquery.validate.js"></script>
	<script type="text/javascript" src="${base}/resources/shop/js/bootstrap.min.js"></script>
<script type="text/javascript">
var base ="${base}";
</script>
<script type="text/javascript">
		$().ready(function() {
		
		var $zoom = $("#zoom");
		var $thumbnail = $("#scrollable a");
		var $specification = $("#specification dl");
		var $specificationTitle = $("#specification div");
		var $specificationValue = $("#specification a");
		var $productNotifyForm = $("#productNotifyForm");
		var $productNotify = $("#productNotify");
		var $productNotifyEmail = $("#productNotify input");
		var $addProductNotify = $("#addProductNotify");
		var $quantity = $("#quantity");
		var $increase = $("#increase");
		var $decrease = $("#decrease");
		var $addCart = $("#addCart");
		var $addFavorite = $("#addFavorite");
		var $window = $(window);
		var $bar = $("#bar ul");
		
		var $introductionTab = $("#introductionTab");
		var $parameterTab = $("#parameterTab");
		var $configurationTab = $("#configurationTab");
		var $auxiliaryDescriptTab = $("#auxiliaryDescriptTab");
		var $schemeImageTab = $("#schemeImageTab");
		var $installStandardTab = $("#installStandardTab");
		var $customerServiceTab = $("#customerServiceTab");
		var $introduction = $("#introduction");
		var $parameter = $("#parameter");
		var $configuration = $("#configuration");
		var $auxiliaryDescript = $("#auxiliaryDescript");
		var $schemeImage = $("#schemeImage");
		var $installStandard = $("#installStandard");
		var $customerService = $("#customerService");
		
		var $addReview = $("#addReview");
		var $addConsultation = $("#addConsultation");
		var barTop = $bar.offset().top;
		var productMap = {};
		var $principalWindow = $("#principalWindow");
		var $changeWood = $(".changeWood");
		var $closeTab = $("#closeTab");
		var $sureBtn = $("#sureBtn");
		var $selectSchemeProductTab = $("#selectSchemeProductTab");
		var schemeProduct = {};
		var selectProduct = {};
		var $selectchange ;
		var $totalChajia = $("#totalChajia");
		var $bespokeBtn = $("#bespokeBtn");
		var $acreageText =$("#acreageText");
		var maximum =parseInt("${scheme.endArea}");
		var minimum =parseInt("${scheme.beginArea}");
		var $sproductTr = $(".sproductTr");
		
		var $selectWK = $("#selectWK");
		var $selectSRQ = $("#selectSRQ");
		var $selectTSB = $("#selectTSB");
		var $selectKZQ = $("#selectKZQ");
		var $WK_TR_ID = $("#WK_TR_ID");
		var $MB_TR_ID = $("#MB_TR_ID");
		var $SRQ_TR_ID = $("#SRQ_TR_ID");
		var $TSB_TR_ID = $("#TSB_TR_ID");
		var $KZQ_TR_ID = $("#KZQ_TR_ID");
		
		var ktId = $("#ktId").val();
		var typeId = $("#typeId").val();
		
		//选择温控、面板
		$selectWK.change(function(){
			var $wkspId = $WK_TR_ID.find("input[name='spId']").val();
			var $wkspPrice = $WK_TR_ID.find(".spPrice");
			var $wknumber = $WK_TR_ID.find(".spNumber").find("input[type='text']").val();
				$wknumber = parseInt($wknumber)+parseInt(1);
			var $wkprice = $WK_TR_ID.find(".price").val();
			
			var $mbspId = $MB_TR_ID.find("input[name='spId']").val();
			var $mbspPrice = $MB_TR_ID.find(".spPrice");
			var $mbnumber = $MB_TR_ID.find(".spNumber").find("input[type='text']").val();
				$mbnumber = parseInt($mbnumber)+parseInt(1);
			var $mbprice = $MB_TR_ID.find(".price").val();
			
			if($selectWK.prop("checked")){
				//查找温控面板计算差价
				var $wksum= parseFloat($wknumber)*parseFloat($wkprice);
				$wkspPrice.text($wksum.toFixed(2));
				
				var $mbsum = parseFloat($mbnumber)*parseFloat($mbprice);
				$mbspPrice.text($mbsum.toFixed(2));
				
				$WK_TR_ID.find(".spNumber").find("input[type='text']").val($wknumber);
				$MB_TR_ID.find(".spNumber").find("input[type='text']").val($mbnumber);
				//计算总价差
				sumTotalPrice();
				sumCostPrice();
				
				$WK_TR_ID.show();
				$MB_TR_ID.show();
			}else{
				$WK_TR_ID.find(".spNumber").find("input[type='text']").val(0);
				$MB_TR_ID.find(".spNumber").find("input[type='text']").val(0);
				$wkspPrice.text("0.00");
				$mbspPrice.text("0.00");
				
				$WK_TR_ID.hide();
				$MB_TR_ID.hide();
				
				//计算总价差
				sumTotalPrice();
				sumCostPrice();
			}
		});
		
		//选择散热器
		$selectSRQ.change(function(){
			var $spPrice = $SRQ_TR_ID.find(".spPrice");
			var $number = $SRQ_TR_ID.find(".spNumber").find("input[type='text']").val();
				$number = parseInt($number)+parseInt(1);
			var $price = $SRQ_TR_ID.find(".price").val();
			if($selectSRQ.prop("checked")){
				var $sum = parseFloat($number)*parseFloat($price);
				$spPrice.text($sum.toFixed(2));
				$SRQ_TR_ID.find(".spNumber").find("input[type='text']").val($number);
				//计算总价差
				sumTotalPrice();
				sumCostPrice();
				
				$SRQ_TR_ID.show();
			}else{
				$SRQ_TR_ID.find(".spNumber").find("input[type='text']").val(0);
				$spPrice.text("0.00");
				$SRQ_TR_ID.hide();
				//计算总价差
				sumTotalPrice();
				sumCostPrice();
			}
		});
		
		//选择提升泵
		$selectTSB.change(function(){
			var $spPrice = $TSB_TR_ID.find(".spPrice");
			var $number = $TSB_TR_ID.find(".spNumber").find("input[type='text']").val();
				$number = parseInt($number)+parseInt(1);
			var $price = $TSB_TR_ID.find(".price").val();
			if($selectTSB.prop("checked")){
				var $sum = parseFloat($number)*parseFloat($price);
				$spPrice.text($sum.toFixed(2));
				$TSB_TR_ID.find(".spNumber").find("input[type='text']").val($number);
				//计算总价差
				sumTotalPrice();
				sumCostPrice();
				
				$TSB_TR_ID.show();
			}else{
				$TSB_TR_ID.find(".spNumber").find("input[type='text']").val(0);
				$spPrice.text("0.00");
				$TSB_TR_ID.hide();
				//计算总价差
				sumTotalPrice();
				sumCostPrice();
			}
		});
		
		//选择控制器
		$selectKZQ.change(function(){
			var $spPrice = $KZQ_TR_ID.find(".spPrice");
			var $number = $KZQ_TR_ID.find(".spNumber").find("input[type='text']").val();
				$number = parseInt($number)+parseInt(1);
			var $price = $KZQ_TR_ID.find(".price").val();
			if($selectKZQ.prop("checked")){
				var $sum = parseFloat($number)*parseFloat($price);
				$spPrice.text($sum.toFixed(2));
				$KZQ_TR_ID.find(".spNumber").find("input[type='text']").val($number);
				//计算总价差
				sumTotalPrice();
				sumCostPrice();
				
				$KZQ_TR_ID.show();
			}else{
				$KZQ_TR_ID.find(".spNumber").find("input[type='text']").val(0);
				$spPrice.text("0.00");
				$KZQ_TR_ID.hide();
				//计算总价差
				sumTotalPrice();
				sumCostPrice();
			}
		});
		
		//更换主材
		$changeWood.click(function(i,the){
			var $the = $(this);
			$selectchange = $the;
			var $id = $the.attr("data_id");
			var $parent = $the.parent().parent();
			var id = $parent.find("input[name='spId']").val();
			var name = $parent.find(".spName").html();
			var brand = $parent.find(".spBrand").html();
			var model = $parent.find(".spModel").html();
			var spPrice = $parent.find(".spPrice").html();
			var category = $parent.find(".spCategory").html();
			var categoryId = $parent.find(".spCategoryId").val();
			var price = $parent.find(".price").val();
			var distType = $parent.find(".distType").val();
			var coeff = $parent.find(".spCoefficient").val();
			var buyNumber = "";
			if(distType == 3){
				buyNumber = $parent.find(".spNumber").find("input[type='text']").val();
			}else{
				buyNumber = 1;
			}
			schemeProduct = {
				id:id,
				name:name,
				brand:brand,
				model:model,
				category:category,
				spPrice:spPrice,
				price:price,
				distType:distType,
				coeff:coeff,
				buyNumber:buyNumber
			};
			//显示主材弹出框
			if(categoryId == null || categoryId == ""){
				$.message("warn","没有更多该主材同分类的主材产品数据，不能更换！");
				return false;
			}
			findSchemeProductCategory(categoryId);
		});
		
		//关闭弹出框
		$closeTab.click(function(){
			$principalWindow.hide();
		});
		
		//确认更换主材按钮
		$sureBtn.click(function(){
			var $input = $("#selectSchemeProductTab").find("input[name='schemeProductId']:checked");
			if($input.length < 1){
				$.message("warn","请选择需要更换的主材产品！");
				return false;
			}
			var $parent = $input.parent().parent();//获取点击所在的行
			var id = $input.val();
			var name = $parent.find(".schemeProductName").html();//主材名称
			var brand = $parent.find(".schemeProductBrand").html();//品牌
			var model = $parent.find(".schemeProductModel").html();//规格
			var category = $parent.find(".schemeProductCategory").html();//分类
			var price = $parent.find("input[name='schemeProductPrice']").val();//单价
			var diff =$parent.find(".schemeDifference").text();
			if(schemeProduct != null && schemeProduct != ""){
				if(schemeProduct.id != id){
					//选择了不同产品
					//计算差价
					var  changeAcreage= $("#acreageText").val();
					if(changeAcreage == null || changeAcreage.replace(/\s+/g,"") == ""){
						$.message("warn","方案面积不能为空！");
					}
					var $tr = $selectchange.parent().parent();
					$tr.find("input[name='spId']").val(id);
					$tr.find(".spName").html(name);//主材名称
					$tr.find(".spBrand").html(brand);//品牌
					$tr.find(".spModel").html(model);//规格
					$tr.find(".spCategory").html(category);//分类
					$tr.find(".spPrice").html(diff);//差价
					$tr.find("input[name='hidChajia']").val(diff);//隐藏差价
					$tr.find("input[name='checked_scheme_price']").val(price);//更换后单价
					if(schemeProduct.distType == 3){
						$tr.find("input[name='spPrice']").val(price);
					}
				}
				//添加到费用栏
				//计算总和
				sumTotalPrice();
				//计算费用明细总和
				sumCostPrice();
			}
			
			$principalWindow.hide();
		});
		
		// 商品图片放大镜
		$zoom.jqzoom({
			zoomWidth: 368,
			zoomHeight: 368,
			title: false,
			showPreload: false,
			preloadImages: false
		});
		
		$thumbnail.hover(function() {
			var $this = $(this);
			if ($this.hasClass("current")) {
				return false;
			} else {
				$thumbnail.removeClass("current");
				$this.addClass("current").click();
			}
		});
		
		//立即预约，加入订单
		$bespokeBtn.click(function() {
			//判断明装、暗装
			var ming = '${mingzhuangId}';
			var an = '${anzhuangId}';
			var fangan = '${scheme.category}';
			var changeNumber = $('#sproductBody .changeNumber').val();
			if((fangan==ming||fangan==an)&&changeNumber==0){
				$.message("warn","明装或者暗装数量不能为零!");
				return false;
			}
			var schemeId = $("#schemeId").val();
			if (!$.checkLogin()) {
				$.redirectLogin("${base}/shop/scheme/content.jhtml?id="+schemeId, "请登录！");
				return false;
			}
			//方案id
			var cartType;
			var quantity = 1;
			//输入方案面积值
			var acreage = parseInt($acreageText.val());
			var $sproductBody =$("#sproductBody");
			var isChange =$sproductBody.attr("data_isChange");//固定方案
			var teHui =$sproductBody.attr("data_isTehui");//特惠方案
			var airConditioner =$("#sproductBody").attr("data_isAirConditioner") == "105" ? true : false;//是否是空调
			var confines =acreage >maximum || acreage < minimum;//是否超出适用方案面积
			if(confines && (airConditioner || teHui || isChange)){
				$.message("warn","请输入方案适用面积范围内数值！");
				return false;
			}
			var schemeProductIds = new Array();
			var check = /^\+?[1-9][0-9]*$/;
			if(acreage != null && acreage != ""){
				if(!check.test(acreage)){
					$.message("warn","请填写有效的整数数字！");
					return false;
				}
			}
			//获取主材ids
			//重新获取主材信息
			var sproductInfos = [];
			$("#sproductBody input[name='spId']").each(function(i,the){
				var $this = $(this);
				var sid = $this.val();
				var $parent = $this.parent();
				var distType = $parent.find("input[name='distType']").val();
				var number = "";
				if(distType == 3){
					number = $parent.find(".spNumber").find("input[type='text']").val();
				}else{
					number = 1;
				}
				var data = {"id":sid,"quantity":number};
				sproductInfos.push(data);
			});
			
			var selectWK = "false";
			var selectSRQ = "false";
			var selectTSB = "false";
			var selectKZQ = "false";
			if($selectWK.prop("checked")){
				selectWK = "true";
			}
			if($selectSRQ.prop("checked")){
				selectSRQ = "true";				
			}
			if($selectTSB.prop("checked")){
				selectTSB = "true";				
			}
			if($selectKZQ.prop("checked")){
				selectKZQ = "true";				
			}
			//采用post
			$("#build_schemeId").val(schemeId);
			$("#build_jsonParam").val(JSON.stringify(sproductInfos));
			$("#build_schemeArea").val(acreage);
			$("#build_isTemperature").val(selectWK);
			$("#build_isDissipate").val(selectSRQ);
			$("#build_isPromote").val(selectTSB);
			$("#build_isController").val(selectKZQ);
			$("#buildScheme").submit();
		});
		
		//定位
		$window.scroll(function() {
			var scrollTop = $(this).scrollTop();
			if (scrollTop > barTop) {
				if (window.XMLHttpRequest) {
					$bar.css({position: "fixed", top: 0});
				} else {
					$bar.css({top: scrollTop});
				}
				var introductionTop = $introduction.size() > 0 ? $introduction.offset().top - 36 : null;
				var parameterTop = $parameter.size() > 0 ? $parameter.offset().top - 36 : null;
				var configurationTop = $configuration.size() > 0 ? $configuration.offset().top - 36 : null;
				var auxiliaryDescriptTop = $auxiliaryDescript.size() > 0 ? $auxiliaryDescript.offset().top - 36 : null;
				var schemeImageTop = $schemeImage.size() > 0 ? $schemeImage.offset().top - 36 : null;
				var installStandardTop = $installStandard.size() > 0 ? $installStandard.offset().top - 36 : null;
				var customerServiceTop = $customerService.size() > 0 ? $customerService.offset().top - 36 : null;
				
				if (introductionTop != null && scrollTop >= introductionTop) {
					$bar.find("li").removeClass("current");
					$introductionTab.addClass("current");
				}else if (parameterTop != null && scrollTop >= parameterTop) {
					$bar.find("li").removeClass("current");
					$parameterTab.addClass("current");
				}else if (configurationTop != null && scrollTop >= configurationTop) {
					$bar.find("li").removeClass("current");
					$configurationTab.addClass("current");
				}else if (auxiliaryDescriptTop != null && scrollTop >= auxiliaryDescriptTop) {
					$bar.find("li").removeClass("current");
					$auxiliaryDescriptTab.addClass("current");
				}else if (schemeImageTop != null && scrollTop >= schemeImageTop) {
					$bar.find("li").removeClass("current");
					$schemeImageTab.addClass("current");
				}else if (installStandardTop != null && scrollTop >= installStandardTop) {
					$bar.find("li").removeClass("current");
					$installStandardTab.addClass("current");
				}else if (customerServiceTop != null && scrollTop >= customerServiceTop) {
					$bar.find("li").removeClass("current");
					$customerService.addClass("current");
				}
			} else {
				$bar.find("li").removeClass("current");
				//$bar.css({position: "absolute", top: barTop});
			}
		});
		
	//计算主材表格中所有主材差价
	function sumTotalPrice(){
		var sum = 0;
		$("#sproductBody tr").each(function(i,the){
			var $the = $(this);
			var price = $the.find(".spPrice").html();
			if(price != null && price != "" && price != 'undefined'){
				sum +=parseFloat(price);
			}
		});
		$("#subtotalPrice").text(sum.toFixed(2));
		$("#zhucaiChajia").html(sum.toFixed(2));
	}
	
	//计算费用表格中所有费用明细差价
	function sumCostPrice(){
		var sum = 0;
		var schemeChajia = $("#schemeChajia").html();
		var zhucaiChajia = $("#zhucaiChajia").html();
		var mianjiChajia = $("#mianjiChajia").html();
		sum = parseFloat(schemeChajia) + parseFloat(zhucaiChajia) + parseFloat(mianjiChajia);
		$("#totalChajia").text(sum.toFixed(2));
		$("#surePrice").text(sum.toFixed(2));
	}
	
	//编辑自选商品数量
	$(".changeNumber").numeral(true).live("input propertychange change",function(event){
		if (event.type != "propertychange" || event.originalEvent.propertyName == "value") {
			var $this = $(this);
			//定位当前tr行上
			var $parent = $this.parent().parent();
			var $price = $parent.find(".price").val();
			var sum = parseFloat($this.val() || 0)*parseFloat($price);
			$parent.find(".spPrice").html(sum.toFixed(2));
			sumTotalPrice();
			sumCostPrice();
		}
	});
	
	
	// 编辑数量
	$acreageText.numeral(true).bind("input propertychange change", function(event) {
		if ((event.type != "propertychange" || event.originalEvent.propertyName == "value") && ktId != typeId) {
			sumDifference();
			//重新计算系数行差值
			var schemeAcreage = $("#schemeAcreage").val();//获取固定方案默认面积
			var acreage = parseInt($acreageText.val() || 0);//当前更改面积
			var $sproductBody =$("#sproductBody");
			var isChange =$sproductBody.attr("data_isChange");//固定方案
			var teHui =$sproductBody.attr("data_isTehui");//特惠方案
			var airConditioner =$("#sproductBody").attr("data_isAirConditioner") == "105" ? true : false;//是否是空调
			var confines =acreage >maximum || acreage < minimum;//是否超出适用方案面积
			if(confines && (airConditioner || teHui || isChange)){
				acreage=minimum;
			}
			var chazhi = Math.abs(schemeAcreage - acreage);//面积差
			$sproductTr.each(function(i,the){
				var $this = $(this);
				var distType = $this.find("input[name='distType']").val();//类型值  1表示有系数  2表示无系数且不能自选  3。表示自选
				var coeff = $this.find("input[name='spCoefficient']").val();//系数
				var chajiaTr = $this.find("input[name='hidChajia']").val();//差价
				var spPrice = $this.find("input[name='checked_scheme_price']").val();//更换后单价
				if(distType == 1){//有系数
					if(coeff != null && coeff != ""){
						var xishucha = chazhi * coeff * spPrice;
						if(parseFloat(schemeAcreage) > parseFloat(acreage)){
							//输入面积大
							xishucha = "-" + xishucha;
						}
						var newChajia = parseFloat(chajiaTr) + parseFloat(xishucha);
						//var scheme_dif_price=parseFloat(newChajia)*parseFloat(checked_scheme_price);
						//newChajia=parseFloat(scheme_dif_price)-parseFloat(chajiaTr);
						$this.find(".spPrice").html(newChajia.toFixed(2));
					}
				}
			});
			//重新计算表格主材差价值
			sumTotalPrice();
			sumCostPrice();
		}
	});
	//计算面积差价
	function sumDifference(){
		//输入面积值
		var acreage = parseInt($acreageText.val());
		var check = /^\+?[1-9][0-9]*$/;
		//面积输入框不为空和空字符串
		if(acreage){
			if(!check.test(acreage)){
				$.message("warn","请填写有效的整数数字！");
				$("input[name='acreage']").focus();
				return false;
			}else{
				var $sproductBody =$("#sproductBody");
				var isChange =$sproductBody.attr("data_isChange");//固定方案
				var teHui =$sproductBody.attr("data_isTehui");//特惠方案
				var airConditioner =$("#sproductBody").attr("data_isAirConditioner") == "105" ? true : false;//是否是空调
				var confines =acreage >maximum || acreage < minimum;//是否超出适用方案面积
				if(confines && (airConditioner || teHui || isChange)){
					acreage=minimum;
				}
				//计算出差价
				//方案规定面积
				var schemeAcreage = $("#schemeAcreage").val();
				//方案辅材单价
				var auxiliaryUnitPrice = $("#auxiliaryUnitPrice").val();
				//方案安装费单价
				var installCost = $("#installCost").val();
				var sumprice = parseFloat(auxiliaryUnitPrice) + parseFloat(installCost);
				var chazhi = Math.abs(schemeAcreage - acreage);
				var sum = chazhi * sumprice;
				sum = sum.toFixed(2);
				if(parseFloat(schemeAcreage) > parseFloat(acreage)){
					//输入面积大
					sum = "-" + sum;
				}
				$("#acreageChajia").text(sum);
				$("#acreageChajiaTr").html(sum);
				$("#mianjiChajia").html(sum);
			}
		}else{
			$("#acreageChajia").text("0.00");
			$("#acreageChajiaTr").html("0.00");
			$("#mianjiChajia").html("0.00");
			sumCostPrice();
		}
	}
	
	/**根据主材分类查询同分类主材**/
	function findSchemeProductCategory(category){
		if(category == null || category == ""){
			$.message("warn","该类型下没有更多主材产品数据，不能更换！");
			return false;
		}
		var $changeSchemeProductList = $("#changeSchemeProductList");
		/**ajax查询*/
		$.ajax({
	 		url:'${base}/shop/scheme/findByCategoryId.jhtml',
	   		dataType:'json',
	   		type:'post',
	   		data:{'categoryId':category},
			success:function(data){
				if(data == null || data.length == 0 ){
					$.message("warn","该类型下没有更多主材产品数据，不能更换！");
					return false;
				}
	    		var htm = "";
	    		if(data == null || data == "null" || data.length == 0 ){
	    			htm += "<tr><td clospan='5'>没有更多主材数据！</td></tr>";
	    			return false;
	    		}else{
	    			for(var i = 0 ; i< data.length; i++){
	    				var cat = data[i];
	    				var acreage = parseInt($acreageText.val()) || 0;
	    				var $sproductBody =$("#sproductBody");
						var isChange =$sproductBody.attr("data_isChange");//固定方案
						var teHui =$sproductBody.attr("data_isTehui");//特惠方案
						var airConditioner =$("#sproductBody").attr("data_isAirConditioner") == "105" ? true : false;//是否是空调
						var confines =acreage >maximum || acreage < minimum;//是否超出适用方案面积
						if(confines && (airConditioner || teHui || isChange)){
	    					acreage=minimum;
	    				}
	    				var diff =sumTotalDiff(schemeProduct.distType,$("#schemeAcreage").val(),schemeProduct.buyNumber,schemeProduct.price,cat.price,schemeProduct.coeff,acreage);
	    				htm += "<tr>";
	    				htm += "<td><input type='radio' name='schemeProductId' value='"+cat.id+"' /></td>";
	    				htm +="<td class='schemeProductName'>"+cat.name+"</td>";
	    				htm +="<td class='schemeProductBrand'>"+cat.brand.name+"</td>";
	    				htm +="<td class='schemeProductModel'>"+cat.specificationValue.name+"</td>";
	    				htm +="<td class='schemeProductCategory'>"+cat.category.title+"</td>";
	    				htm +="<td class='schemeDifference'>"+diff.toFixed(2)+"</td>";
	    				htm +="<input type='hidden' name='schemeProductPrice' value='"+cat.price+"' />";
	    				htm += "</tr>";
	    			}
	    		}
	    		$changeSchemeProductList.html(htm);
	    		$("#principalWindow").show();
	   		},
	   		error:function(err){
	   			$.message("warn","数据查询失败！");
	   			return false;
	   		}
	    });
	}
//新的计算差价方法
function sumTotalDiff(distType,acreage,buyNumber,price,changePrice,coeff,changeAcreage){
	//根据类型计算不同类型差价值
	if(distType == 1){
	//有系数值差价计算
		//获取面积值
		//获取更换前主材价格
		//获取更换后主材价格
		//获取系数值
		if(acreage == changeAcreage){
			//没有更改面积的情况下
			var cha = parseFloat(changePrice)-parseFloat(price);
			return parseFloat(acreage*coeff*cha);
		}else{
			//计算现在的金额
			var nowprice = parseFloat(changeAcreage)*parseFloat(changePrice)*parseFloat(coeff);
			//原始金额
			var oldprice = parseFloat(acreage)*parseFloat(price)*parseFloat(coeff);
			return parseFloat(nowprice) - parseFloat(oldprice);
		}
	}else if(distType == 2){
		//无系数值差价计算
		return parseFloat(changePrice)-parseFloat(price);
		//获取更换前主材价格
		//获取更换后主材价格
		
	}else if(distType == 3){
		//自选产品差价计算
		//获取购买数量
		//自选主材单价
		if(changePrice != null && changePrice != "" && buyNumber != null && buyNumber != ""){
			return parseFloat(changePrice) * parseFloat(buyNumber);
		}
		return 0;
	}
}
});
</script>
</html>